/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.search;

import br.com.deployment.daoImpl.NotaryOfficeDAOImpl;
import br.com.deployment.entities.Address;
import br.com.deployment.entities.NotaryOffice;
import br.com.deployment.manager.create.ManagerCreateQuestionnaire;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author ely
 */
@ManagedBean
@SessionScoped
public class ManagerSearchNotaryOffice {
    
    @EJB
    NotaryOfficeDAOImpl notaryService;
    
    // Lista de todos os cartórios
    private List<NotaryOffice> notaryOffices;
    
    // Lista de todos os cartórios da pesquisa
    public List<NotaryOffice> searchLstNotaryOffices;
    
    // Objeto cartório
    private NotaryOffice notaryOffice;
    
    // Objeto da pesquisa
    private NotaryOffice notary;
    
    // Objeto Endereço
    private Address address;
    
    public ManagerSearchNotaryOffice(){
        
    }
    
    @PostConstruct
    public void init(){
        notaryOffices       = new ArrayList<NotaryOffice>();
        notary              = new NotaryOffice();
        searchLstNotaryOffices = new ArrayList<NotaryOffice>();
    }
    
    public List<NotaryOffice> lstNotaryOffices(){
        return notaryOffices = notaryService.findAll();
    }
    
    public void searchNotaryOffice(){
        searchLstNotaryOffices = notaryService.findNotaryOffice(notary);
    }
    
     // Pega o Objeto Cartório Selecionado e redireciona a Página
     public void redirect(String string, NotaryOffice n) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            this.notaryOffice = n;
            this.address = notaryOffice.getAddress();
            context.getExternalContext().redirect(string);
        } catch (IOException ex) {
            Logger.getLogger(ManagerCreateQuestionnaire.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    

    public List<NotaryOffice> getNotaryOffices() {
        return notaryOffices;
    }

    public void setNotaryOffices(List<NotaryOffice> notaryOffices) {
        this.notaryOffices = notaryOffices;
    }

    public NotaryOffice getNotaryOffice() {
        return notaryOffice;
    }

    public void setNotaryOffice(NotaryOffice notaryOffice) {
        this.notaryOffice = notaryOffice;
    }

    public List<NotaryOffice> getSearchLstNotaryOffices() {
        return searchLstNotaryOffices;
    }

    public void setSearchLstNotaryOffices(List<NotaryOffice> searchLstNotaryOffices) {
        this.searchLstNotaryOffices = searchLstNotaryOffices;
    }

 
    public NotaryOffice getNotary() {
        return notary;
    }

    public void setNotary(NotaryOffice notary) {
        this.notary = notary;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }
    
    
}
